// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init()
const db =  cloud.database()
const postco = db.collection('post')
// 云函数入口函数
exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext()
  console.log('postid 为：'+event.postid)

  try {
    return await postco.where({
      _id:event.postid
    }).remove()
    .then(res=>{
      console.log('删除post成功!'+res)
    }).catch(err=>{
      console.log('删除post失败！'+err)
    })
    
  } catch (error) {
    console.log(error)
  }

  return {
    event,
    openid: wxContext.OPENID,
    appid: wxContext.APPID,
    unionid: wxContext.UNIONID,
  }
}